CreateGroup Method Example

This example uses the CreateGroup method to create a new Group object; it then makes the "admin" user a member of the new Group object and lists its properties and users.

Sub CreateGroupX()

    Dim wrkDefault As Workspace
    Dim grpNew As Group
    Dim grpTemp As Group
    Dim prpLoop As Property
    Dim usrLoop As User

    Set wrkDefault = DBEngine.Workspaces(0)

    With wrkDefault

        ' Create and append new group.
        Set grpNew = .CreateGroup("NewGroup", _
            "AAA123456789")
        .Groups.Append grpNew

        ' Make the user "admin" a member of the
        ' group NewGroup by creating and adding the
        ' appropriate Group object to the user's Groups
        ' collection.
        Set grpTemp = .Users("admin").CreateGroup("NewGroup")
        .Users("admin").Groups.Append grpTemp

        Debug.Print "Properties of " & grpNew.Name

        ' Enumerate the Properties collection of NewGroup. The 
        ' PID property is not readable.
        For Each prpLoop In grpNew.Properties
            On Error Resume Next
            If prpLoop <> "" Then Debug.Print "  " & _
                prpLoop.Name & " = " & prpLoop
            On Error GoTo 0
        Next prpLoop

        Debug.Print "Users collection of " & grpNew.Name

        ' Enumerate the Users collection of NewGroup.
        For Each usrLoop In grpNew.Users
            Debug.Print "  " & _
                usrLoop.Name
        Next usrLoop

        ' Delete the new Group object because this
        ' is a demonstration.
        .Groups.Delete "NewGroup"

    End With

End Sub